{extend name="layout" /}
{block name="content"}
<div class="layui-tab layui-tab-brief">
	<ul class="layui-tab-title">
	    <li class="layui-this">{$pathCurrent['name']}</li>
	    <li><a href="{:url('option')}">添加微信</a></li>
  	</ul>
</div>

<div class="demoTable" style="margin-top: 25px;margin-left:20px;">
	关键词：
	<div class="layui-inline" style="width:200px;">
		<input class="layui-input" name="title" id="title" placeholder="微信号" autocomplete="off">
	</div>
	<div class="layui-inline">
		<form class="layui-form">
			<select class="layui-input" name="urlid" id="urlid" lay-filter="cid">
				<option value="">请选择域名</option>
				{foreach $Scurl as $vo}
				<option value="{$vo['id']}">{$vo['url']}</option>
				{/foreach}
			</select>
		</form>
	</div>
	<div class="layui-inline">
		<form class="layui-form">
			<select class="layui-input" name="state" id="state" lay-filter="cid">
				<option value="">是否上线</option>
				<option value="1">是</option>
				<option value="0">否</option>
				
			</select>
		</form>
	</div>
	<button class="layui-btn" data-type="reload">搜索</button>
</div>
<div class="layui-card-body">
	<div data-model="table-bind">
		<table class="layui-hide" id="data_table" lay-filter="data_table" data-table></table>
	</div>
</div>
<script type="text/html" id="barTar">
	<a class="layui-btn layui-btn-xs" href="{{d.op}}">编辑</a>
	{{# if(d.image){ }}
	<a class="layui-btn layui-btn-xs" data.src="d.image" lay-event="son" >二维码预览</a>
	{{# } }}
  	<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del" data-del data-id="{{d.id}}" data-table="user">删除</a>
</script>
<script type="text/html" id="image">
	<img src="{{d.image}}" height="30">
</script>
<script type="text/html" id="sysTar">
	{{#  if(d.state == 1){ }}
  	<button type="button" lay-event="status"  data-id="{{d.id}}" class="layui-btn layui-btn-normal">启用</button>
  	{{#  } else { }}
  	<button type="button" lay-event="status"  data-id="{{d.id}}" class="layui-btn layui-btn-danger">冻结</button>
  	{{#  } }}
</script>
{/block}
{block name="js"}
<script type="text/javascript">
var mixin = {};
var SlefUrl = this.location.href;
layui.use(['table','upload'], function(){
	var table = layui.table;
	var upload = layui.upload;
	table.render({
		elem: '#data_table',
		url:SlefUrl,
		limit:20,
		cellMinWidth: 80,
		cols: [[
	      	{field:'id',width:80, title: 'ID', sort: true,align:'center'}
	      	,{field:'weixin', title: '微信', width:280,align:'center'}
	      	,{field:'url', title: '域名'}
	      	,{field:'state', width:100, title: '状态',toolbar: '#sysTar'}
	      	,{field:'op', title: '操作',toolbar: '#barTar', width:400,align:'center'}
	    ]],
	    page: true,
        id: 'testReload'
	});
	table.on('tool(data_table)', function(obj){
		var data = obj.data;
		data.table = "customer";
		if(obj.event === 'del'){
			layer.confirm('确定删除吗？', function(index){
	        	layer.close(index);
	       		form.formDel(data,obj);
	      	});
		}

		 if(obj.event === 'son'){
			var result = {};
			result['id'] = data.image
				
				var str = 'data.image';
				//一个公告层
				layer.open({
					type: 1
					,area:['600px','500px']
					,offset: 'auto' //具体配置参考：http://www.layui.com/doc/modules/layer.html#offset
					,id: 'layerDemoauto' //防止重复弹出
					,content: '<div style="padding: 50px 0 0 150px;"><img src="'+ data.image +'" alt=""> </div>'
					,btn: '关 闭'
					,btnAlign: 'c' //按钮居中
					,shade: 0 //不显示遮罩
					,yes: function(){
					layer.closeAll();
					}
				});
		      
	    }

			if(obj.event === 'status'){
				layer.confirm('确定修改状态吗？', function(index){
							var result = {};
							result = data;
							$.post('{:url("status")}',result,function(res){
									if( res.code == 1 ){
										window.location.reload();
									}else{
										alert(res.msg);
									}
							},'json')
				});
			}


	});
    var $ = layui.$, active = {
        reload: function(){
            var title = $('#title');
            var urlid = $('#urlid');
            var state = $('#state');

            //执行重载
            table.reload('testReload', {
                page: {
                    curr: 1 //重新从第 1 页开始
                }
                ,where: {
										title: title.val(),
										state: state.val(),
										urlid: urlid.val()
                }
            }, 'data');
        },
		excelDemo: function(){
            window.location.href = '/excel/product_demo.xls'
        }
    };

	upload.render({
		elem: '#uploadExcel'
		,url: '{:url("savestudentImport")}'
		,accept: 'file' //普通文件
		,auto:'xlsx|xls|csv'
		,done: function(res){
			layer.alert(res.msg);
			// setInterval(function(){
			// 	window.location.reload();
			// },3000)
			
		}
	});

    $('.demoTable .layui-btn').on('click', function(){
        var type = $(this).data('type');
        active[type] ? active[type].call(this) : '';
    });

	$('#excelDemo').on('click', function(){
        var type = $(this).data('type');
        active[type] ? active[type].call(this) : '';
    });



});
</script>
{/block}